<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./script/Cesium/Cesium.js"></script>
    <link rel="stylesheet" href="./script/Cesium/Widgets/widgets.css" />
    <style>
      html,
      body {
        height: 100%;
        margin: 0px;
        padding: 0px;
      }
    </style>
  </head>
  <body>
    <div id="cesiumContainer" style="width: 100%"></div>
    <script>
      const viewer = new Cesium.Viewer("cesiumContainer", {
        // baseLayerPicker: false,
        // navigationHelpButton: false,
        // sceneModePicker: false,
        terrainProvider: Cesium.createWorldTerrain(),
        baseLayerPicker: false,
        shouldAnimate: true,
      });

      function getCzml() {
        var czml = [
          {
            id: "document",
            name: "CZML Path",
            version: "1.0",
            clock: {
              interval: "2012-08-04T10:00:00Z/2012-08-04T10:01:00Z",
              currentTime: "2012-08-04T10:00:00Z",
              multiplier: 10,
            },
          },
          {
            id: "path",
            name: "path with GPS flight data",
            description:
              "<p>Hang gliding flight log data from Daniel H. Friedman.<br>Icon created by Larisa Skosyrska from the Noun Project</p>",
            availability: "2012-08-04T10:00:00Z/2012-08-04T10:01:00Z",
            path: {
              material: {
                polylineOutline: {
                  color: {
                    rgba: [255, 0, 255, 255],
                  },
                  outlineColor: {
                    rgba: [0, 255, 255, 255],
                  },
                  outlineWidth: 5,
                },
              },
              width: 8,
              leadTime: 10,
              trailTime: 1000,
              resolution: 5,
            },
            billboard: {
              image:
                "",
              scale: 1.5,
              eyeOffset: {
                cartesian: [0.0, 0.0, -10.0],
              },
            },
            position: {
              epoch: "2012-08-04T10:00:00Z",
              cartographicDegrees: [
                0,
                -122.93797,
                39.50935,
                200000,
                10,
                -122.93822,
                39.50918,
                200000,
                20,
                -122.9385,
                39.50883,
                200000,
                30,
                -122.93855,
                39.50842,
                200000,
                40,
                -122.93868,
                39.50792,
                200000,
                50,
                -122.93877,
                39.50743,
                200000,
                60,
                -122.93862,
                39.50697,
                200000,
                70,
                -122.93828,
                39.50648,
                200000,
                80,
                -122.93818,
                39.50608,
                200000,
                90,
                -122.93783,
                39.5057,
                200000,
                100,
                -122.93777,
                39.50513,
                200000,
                110,
                -122.93793,
                39.50458,
                200000,
                120,
                -122.93815,
                39.50415,
                200000,
                130,
                -122.9382,
                39.50362,
                200000,
                140,
                -122.93818,
                39.5031,
                200000,
                150,
                -122.93812,
                39.50258,
                200000,
                160,
                -122.93792,
                39.5022,
                200000,
                170,
                -122.93775,
                39.50177,
                200000,
                180,
                -122.93745,
                39.50125,
                200000,
                190,
                -122.93723,
                39.50073,
                200000,
                200,
                -122.9373,
                39.50023,
                200000,
                210,
                -122.93705,
                39.49987,
                200000,
                220,
                -122.93642,
                39.4996,
                200000,
                230,
                -122.93593,
                39.49927,
                200000,
                240,
                -122.936,
                39.49895,
                200000,
                250,
                -122.93645,
                39.49907,
                200000,
                260,
                -122.93685,
                39.49915,
                200000,
                270,
                -122.93708,
                39.4989,
                200000,
                280,
                -122.93687,
                39.49843,
                200000,
                290,
                -122.93685,
                39.49808,
                200000,
                300,
                -122.93722,
                39.49815,
                200000,
                310,
                -122.93712,
                39.49867,
                200000,
                320,
                -122.93633,
                39.49893,
                200000,
                330,
                -122.93615,
                39.4989,
                200000,
                340,
                -122.936,
                39.49885,
                200000,
                350,
                -122.93587,
                39.49877,
                200000,
                360,
                -122.93577,
                39.49868,
                200000,
                370,
                -122.93568,
                39.4986,
                200000,
                380,
                -122.93563,
                39.49853,
                200000,
                390,
                -122.9356,
                39.49845,
                200000,
                400,
                -122.9356,
                39.4984,
                200000,
                410,
                -122.93562,
                39.49835,
                200000,
                420,
                -122.93565,
                39.4983,
                200000,
                430,
                -122.93568,
                39.49827,
                200000,
                440,
                -122.93572,
                39.49822,
                200000,
                450,
                -122.93575,
                39.49817,
                200000,
                460,
                -122.93577,
                39.49812,
                200000,
                470,
                -122.93578,
                39.49805,
                200000,
                480,
                -122.93573,
                39.498,
                200000,
                490,
                -122.93567,
                39.49795,
                200000,
                500,
                -122.93555,
                39.4979,
                200000,
                510,
                -122.9354,
                39.49788,
                200000,
                520,
                -122.93522,
                39.49792,
                200000,
                530,
                -122.93502,
                39.49795,
                200000,
                540,
                -122.93492,
                39.4981,
                200000,
                550,
                -122.93483,
                39.49827,
                200000,
                560,
                -122.93485,
                39.49842,
                200000,
                570,
                -122.93493,
                39.49855,
                200000,
                580,
                -122.93502,
                39.49868,
                200000,
                590,
                -122.93517,
                39.4987,
                200000,
                600,
                -122.9353,
                39.49873,
                200000,
              ],
            },
          },
        ];
        return czml;
      }

      function startUp2() {
        console.log("x");
        const czml = getCzml();

        const dataSourcePromise = Cesium.CzmlDataSource.load(czml);
        dataSourcePromise.then((dataSource) => {
          const entity = dataSource.entities.getById("launchvehicle");

          console.log(entity);

          viewer.trackedEntity = ds.entities.getById("path");

          //setRotate(entity, { rotateX: 100, rotateY: 100, rotateZ: 100 });
          //update3dtilesMaxtrix(entity);
          setModelMatrix(entity);
        });
        viewer.dataSources.add(dataSourcePromise);
        viewer.zoomTo(dataSourcePromise);

        // viewer.camera.setView({
        //   destination: new Cesium.Cartesian3(-122.9353, 39.49873, 700000),
        // });
      }

      startUp2();

      function startUp() {
        const czml = getCzml();

        viewer.dataSources
          .add(Cesium.CzmlDataSource.load(czml))
          .then(function (ds) {
            viewer.trackedEntity = ds.entities.getById("path");
          });
      }

      startUp();
    </script>
  </body>
</html>
